/*
 * @lc app=leetcode.cn id=606 lang=javascript
 *
 * [606] 根据二叉树创建字符串
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} t
 * @return {string}
 */
var tree2str = function(t) {


    function pre(t){
        let ret="";
        if(t===null)return ret;
        ret += t.val;
        if(t.left!==null){
            ret += "("+ pre(t.left)+")"
            if(t.right!==null){
                ret+="("+pre(t.right)+")";
            }
        }else if(t.right!==null){
            ret+="()("+pre(t.right)+")";
        }
        return ret;

    }

    return  pre(t);


    
};
// @lc code=end

